<template>
  <div class="tanxing">
    <div class="zuo">
      <p class="zuowen">欢迎光临</p>
    </div>
    <div class="you">
      <p class="youwen">欢迎回来</p>
      <span>账号密码登录</span>
      <el-form :model="formData">
        <el-form-item>
          <el-input placeholder='请输入账户名' v-model="formData.username" />
        </el-form-item>
        <el-form-item>
          <el-input placeholder='请输入密码' v-model="formData.password" />
        </el-form-item>
      </el-form>
      <el-button @click="onSubmit" :plain="true" type="primary">登录</el-button>
    </div>
  </div>
</template>

<script setup>
import { reactive } from 'vue'
import { PostLoginApi } from '@/api/login';
import router from '@/router';

const formData = reactive({
  username: 'admin',
  password: 'admin'
})

const onSubmit = async () => {
  const {msg,data} = await PostLoginApi(formData)
  if (msg === 'ok') {
    router.push('/')
    localStorage.setItem('user-token', data.token);
    ElMessage({
      message: '登陆成功',
      type: 'success',
    })
  }
  console.log(msg,data.token)
}
</script>

<style scoped>
span{
  color: #eceae9;
  font-size: 12px;
}

.tanxing{
  display: flex;
  height: 100%;
}

.zuo{
  background-color:#6366f1;
  width: 70%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 20px;
  font-weight: 900;
}

.zuowen{
  text-align: center;
  color: #fdfdfd;
}

.you{
  background-color:#fdfdfd;
  width: 30%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-size: 20px;
  font-weight: 900;
}

.yuowen{
  font-size: 18px;
  font-weight: 900;
}

/* 去除间距 */
body,ul,ol,p,h1,h2,h3,h4,h5,h6,input,dl,dd,fieldset,legend,figure,figcaption{
  margin: 0;
  padding: 0;
}

</style>